package com.ccs.demo;

import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpSession;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RequestMapping("user")
@RestController
public class UserNew {
    public Boolean login(String userName, String password, HttpSession session){
//        1.参数校验
//        2.验证密码是否正确
//        3.进行返回
        if(!StringUtils.hasLength(userName) ||! StringUtils.hasLength(password) ){
            return false;
        }
        //验证密码正常性
        if("admin".equals(userName) && "admin".equals(password)){
            return true;
        }
        return false;
    }

    @GetMapping("getLoginUser")
    public String getLoginUser(HttpServletRequest request){
        HttpSession session=request.getSession(false);
        if(session==null){
            return "";
        }
        return (String)session.getAttribute("loginUserName");
    }

}
